package com.hentica.app.component.photo;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.hentica.imagecompress.Option;

import java.util.List;

/**
 * Created by pxy on 2018/2/25.
 */

public class PhotoManager implements TakePhotoCallBack {
    private TakePhoto mTakePhoto;
    private CropOption option = new CropOption();
    private Option mCompressOption = new Option();
    private boolean isCrop = true;
    private boolean isCompross = true;
    private PhotoManager.PhotoCallBack lisenter;

    public PhotoManager() {
    }

    public PhotoManager(CropOption option) {
        this.option = option;
    }

    public static PhotoManager PhotoManager() {
        return new PhotoManager();
    }

    public PhotoManager(PhotoManager.PhotoCallBack callBack) {
        this.lisenter = callBack;
    }

    public void camera(Activity activity, boolean isCrop) {
        this.mTakePhoto = new TakePhotoCamera(activity, isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void camera(Fragment fragment, Activity activity) {
        this.mTakePhoto = new TakePhotoCamera(fragment, activity, this.isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void selectPic(Activity activity, boolean isCrop) {
        this.mTakePhoto = new TakePhotoAlbum(activity, isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void camera(Activity activity) {
        this.mTakePhoto = new TakePhotoCamera(activity, this.isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void selectPic(Activity activity) {
        this.mTakePhoto = new TakePhotoAlbum(activity, this.isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void selectPic(Fragment fragment, Activity activity) {
        this.mTakePhoto = new TakePhotoAlbum(fragment, activity, this.isCrop, this.option, this.isCompross, this.mCompressOption, this);
        this.mTakePhoto.takePhoto();
    }

    public void handleActivityResult(int requestCode, int resultCode, Intent data) {
        if (this.mTakePhoto != null) {
            this.mTakePhoto.handleActivityResult(requestCode, resultCode, data);
        }

    }

    public void onDetch() {
        this.mTakePhoto.detch();
        this.mTakePhoto = null;
    }

    public void setPhotoCallBack(PhotoManager.PhotoCallBack lisenter) {
        this.lisenter = lisenter;
    }

    public void getPhotos(List<String> photos) {
        Log.d("dwqdwqdwq", "manager传入了");
        if (this.lisenter != null) {
            this.lisenter.getPhotos(photos);
            this.lisenter.dismissDialog();
        }

    }

    public void error() {
        Log.d("dwqdwqdwq", "manager报错了");
        if (this.lisenter != null) {
            this.lisenter.error();
            this.lisenter.dismissDialog();
        }

    }

    public PhotoManager setOption(CropOption option) {
        this.option = option;
        return this;
    }

    public PhotoManager setCompressOption(Option mCompressOption) {
        this.mCompressOption = mCompressOption;
        return this;
    }

    public PhotoManager setCrop(boolean crop) {
        this.isCrop = crop;
        return this;
    }

    public PhotoManager setCompross(boolean compross) {
        this.isCompross = compross;
        return this;
    }

    public interface PhotoCallBack {
        void getPhotos(List<String> var1);

        void error();

        void dismissDialog();
    }
}